
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.admin.util.ChainUtil;
import com.cxtj.CxBean;
import com.cxtj.CxtjController;
import com.cxtj.CxtjDAO;
import com.cxtj.EtlBean;
import com.cxtj.UserDAO;
import com.spring.task.ChainorcDao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


	@RunWith(SpringJUnit4ClassRunner.class)
	@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class MvcTest {
		  
		  @Resource(name = "CxtjDAO")
		  CxtjDAO cxDao;	
		  @Resource(name = "UserDAO")
		  UserDAO userDAO; 
		  @Resource(name = "ChainorcDao")
		  ChainorcDao coDao;
	  /*
*/
		@Test
		public void test() throws Exception {
			System.out.println("正在获取ETL配置表......");	
			List<EtlBean> tbList = userDAO.getEtlRec();
			System.out.println("ETL配置表获取完成，正在根据ETL配置从Oracle或者数据......");					
			List<CxBean> cxList=coDao.getCxListByTableAndUser(tbList);		
			System.out.println("数据获取完成，正在根据ETL配置从Oracle或者数据......");
			if(cxList!=null && cxList.size()>0)
			{
				System.out.println("已获取数据数量："+cxList.size()+"正在向区块链插入数据......");
				ChainUtil cu = new ChainUtil();		
				String res = cu.insertList2Chain(cxList);
				System.out.println("向区块链插入数据："+res);
			}
			else{
				System.out.println("无最新数据。");
			}
			List<EtlBean> tbList2=cxDao.getETL(tbList);
			System.out.println("正在更新ETL配置表......");
			for(EtlBean tb:tbList2){
				System.out.println(userDAO.updateETL(tb));
			}
			
		//	System.out.println(ret);
	//		List<Map<String, Object>> tList = cxDao.getMaxDateList(ls);		/*			

			/*for(EtlBean tbs:tbList){	
				List<CxBean>  res=coDao.getCxListByTableName(tbList);
				cxs.addAll(res);
				Map<String, Object> tm = new HashMap<String, Object>();
				tm.put("tablename", res.get(0).getOBJ_NAME());
				tm.put("datetime", res.get(0).getCzsj());
				timeList.add(tm);
			}		*/	
	//		List<CxBean>  res=coDao.getCxListByTableName(tbList);			

	//		System.out.println("修改记录："+coDao.Ora2Chain());
	//		String Str = cxDao.getMaxDate().get("maxDate").toString();	
/*			Timestamp ts = Timestamp.valueOf(Str);
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String dateStr = sdf.format(ts);
			System.out.println("Date："+sdf.format(ts));
			List<CxBean> cxList = coDao.getCxList(dateStr,null);*/
/*			HashMap<String, Object> cxList = cxDao.selectPage(null,null,null,null,null);
			System.out.println("修改记录："+cxList.get("datas").toString());*/
			/*ChainUtil cu = new ChainUtil();		
			String res = cu.insertList2Chain(cxList);
			System.out.println(res);*/
		/*	List<Map<String, Object>> datas = cxDao.getBarData();		
			System.out.println("修改记录："+datas);
			List<String> items = new ArrayList<String>();
			List<Integer> curMon = new ArrayList<Integer>();
			List<Integer> oneMon = new ArrayList<Integer>();
			List<Integer> twoMon = new ArrayList<Integer>();
			for(Map<String, Object> map:datas){
				items.add(map.get("name").toString());
				if(map.get("curMon")!=null){
					curMon.add(Integer.parseInt(map.get("curMon").toString()));
				}else{
					curMon.add(0);
				}
				if(map.get("oneMon")!=null){
					oneMon.add(Integer.parseInt(map.get("oneMon").toString()));
				}else{
					oneMon.add(0);
				}
				if(map.get("twoMon")!=null){
					twoMon.add(Integer.parseInt(map.get("twoMon").toString()));			
				}else{
					oneMon.add(0);
				}
			}
			System.out.println("修改记录："+curMon);
			System.out.println("修改记录："+oneMon);
			System.out.println("修改记录："+twoMon);*/
		//	cxDao.selectPage(null,null);
		/*	String[] bArray = {"a","b","c", "d", "e"}; 
			List lis = new ArrayList<String>();
			lis.add("qwe");
			lis.add("asd");
			System.out.println(lis);*/
		//	System.out.println(bArray.toString());
			
		}
		 
}  


	